package com.xmb.wechat.view.qq;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.definterface.HintListener;
import com.xmb.wechat.view.alipay.AliPayTransferActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/21 09:33
 */
public class QQTransferActivity extends BaseActivity {

    @BindView(R2.id.tv_received)
    TextView     mTvReceived;
    @BindView(R2.id.tv_transfer)
    TextView     mTvTransfer;
    @BindView(R2.id.et_balance)
    EditText     mEtBalance;
    @BindView(R2.id.et_nickName)
    EditText     mEtNickName;
    @BindView(R2.id.ll_nickName)
    LinearLayout mLlNickName;

    private boolean mIsTransfer;

    public QQTransferActivity() {
        super(R.layout.activity_qq_transfer);
    }

    @Override
    protected void initView() {
        setTransferType(false);
        showExemption(new HintListener() {
            @Override
            public void onConfirm() {
                //do nothing
            }

            @Override
            public void onCancel() {
                QQTransferActivity.this.finish();
            }
        });
    }

    @OnClick({R2.id.tv_received, R2.id.tv_transfer, R2.id.btn_preview})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.tv_received) {
            setTransferType(false);
        } else if (id == R.id.tv_transfer) {
            setTransferType(true);
        } else if (id == R.id.btn_preview) {
            String money = mEtBalance.getText().toString().trim();
            if (TextUtils.isEmpty(money)) {
                ToastUtils.showShort("请填写转账金额");
                return;
            }
            String nickName = "";
            if (mIsTransfer) {
                nickName = mEtNickName.getText().toString().trim();
                if (TextUtils.isEmpty(nickName)) {
                    ToastUtils.showShort("请填写对方昵称");
                    return;
                }
            }
            QQTransferDetailActivity.start(this, mIsTransfer, money, nickName);
        }
    }

    private void setTransferType(boolean isTransfer) {
        mTvReceived.setSelected(!isTransfer);
        mTvTransfer.setSelected(isTransfer);
        mIsTransfer = isTransfer;
        mLlNickName.setVisibility(isTransfer ? View.VISIBLE : View.GONE);
    }
}
